package cn.hchaojie.javase.day04;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
 * junit 里面assert（断言）的使用
 */
import org.junit.Test;

public class ContinuousFour {
	@Test
	public void test() {
		// 边缘情况
		int[] numbers1 = {8,9,9,9,9,8};
		int[] numbers2 = {8,9,9,9,8};
		int[] numbers3 = {9,9,9,9,8};
		int[] numbers4 = {9,9,9,9};
		int[] numbers5 = {8, 9,9,9,9};
		int[] numbers6 = {8,8,9,9,9};
		
		assertTrue(hasContinuousfour(numbers1));
		assertFalse(hasContinuousfour(numbers2));
		assertTrue(hasContinuousfour(numbers3));
		assertTrue(hasContinuousfour(numbers4));
		assertTrue(hasContinuousfour(numbers5));
		assertFalse(hasContinuousfour(numbers6));
	}
	
	public static boolean hasContinuousfour(int[] numbers) {
		int flag = 0;
		for (int i = 0; i < numbers.length - 1; i++) {
			if (numbers[i] != numbers[i + 1])
				flag = 0;
			else {
				flag++;
				if (flag == 3) {
					return true;
				}
			}
		}
		return false;
	}
}
